'''
计算

累加求和 1到100
'''
num = 0
sum = 0
while num <= 100:
    sum += num
    num += 1
print(sum)


'''
打印 1 到100 以内的所有奇数，形成列表
'''
list_of_odd_numbers = []
list = range(1, 101)
for i in list:
    if i % 2 != 0:
        list_of_odd_numbers.append(i)
print(list_of_odd_numbers)

'''
嵌套循环

计算：1!-2!+3!-4!+.....+49!-50!
'''

print(f'\n " ===========嵌套循环和函数学习==============" \n')

# 这是在计算阶乘


def factorial(n):
    if n == 0 or n == 1:
        return 1
    else:
        return n * factorial(n-1)


i = 1
result = 0
while i < 51:
    # 这是在计算阶乘
    fact = factorial(i)

    if i % 2 == 0:
        result -= fact
    else:
        result += fact
    i += 1

print(f'result = {result}')
